import datetime

from src.application.user import dto
from src.application.user.use_cases import SetTestProxyAcquired, SetTestProxyAcquiredHandler
from src.domain.user.aggregates import UserAggregate
from src.domain.user.value_objects import TelegramUserId, UserId
from tests.mocks.uow import UnitOfWorkMock
from tests.mocks.user_repo import UserRepoMock


async def test_correct_set_test_proxy_acquired(
    uow: UnitOfWorkMock,
    user_repo: UserRepoMock,
) -> None:
    handler = SetTestProxyAcquiredHandler(uow=uow)
    user_id = 123
    user = UserAggregate(id=UserId(0), tg_id=TelegramUserId(user_id), username="username")
    user_repo.users[user.tg_id] = user

    test_proxy_acquired = datetime.datetime.now()
    command = SetTestProxyAcquired(tg_user_id=user_id, test_proxy_acquired=test_proxy_acquired)

    result = await handler(command=command)

    assert isinstance(result, dto.UserDTO)
    assert result.tg_id == user_id
    assert result.test_proxy_acquired == test_proxy_acquired
    assert uow.commit_status is True
    assert uow.rollback_status is False
